#include "custom_qdialog.h"

CustomDialog::CustomDialog() {
    CreateMainWindow();
    this -> setStyleSheet("\
        QDialog {\
            background-color: #888888;\
        }\
        QLabel {\
            color: #F0F0F0;\
            font-size: 14px;\
        }\
        QPushButton {\
            width: 40px;\
            height: 20px;\
            background-color: #F0F0F0;\
            color: #444444;\
            border-radius: 5px;\
        }");
}

CustomDialog::~CustomDialog() {
    delete isOSSSelected;
    delete isQiNiuSelected;
    delete acceptButton;
    delete selectLayout;
    delete buttonLayout;
    delete layout;
}

void CustomDialog::CreateMainWindow() {
    setWindowTitle("Select The Backend");
    setWindowIcon(QIcon(":/material/Ui/cloud_storage.png"));

    setMinimumSize(200, 100);
    setMaximumSize(200, 100);

    SetWidgets();
}

void CustomDialog::SetWidgets() {
    isOSSSelected = new QRadioButton();
    isOSSSelected -> setChecked(true);
    isQiNiuSelected = new QRadioButton();
    isQiNiuSelected -> setChecked(false);

    selectLayout = new QGridLayout();
    selectLayout -> addWidget(isOSSSelected, 0, 0, 1, 1);
    selectLayout -> addWidget(new QLabel("OSS"), 0, 1, 1, 1);
    selectLayout -> addWidget(isQiNiuSelected, 0, 2, 1, 1);
    selectLayout -> addWidget(new QLabel("QiNiu"), 0, 3, 1, 1);

    acceptButton = new QPushButton("Ok");
    connect(acceptButton, SIGNAL(clicked(bool)), this, SLOT(accept()));

    buttonLayout = new QHBoxLayout();
    buttonLayout -> addStretch();
    buttonLayout -> addWidget(acceptButton);

    layout = new QVBoxLayout();
    layout -> setContentsMargins(30, 20, 30, 10);
    layout -> addLayout(selectLayout);
    layout -> addSpacing(10);
    layout -> addLayout(buttonLayout);

    this -> setLayout(layout);
}

void CustomDialog::accept() {
    QDialog::accept();
}
